		<link rel="stylesheet" href="__PUBLIC__/css/editor.css"> 
		<link rel="stylesheet" href="__PUBLIC__/css/editor_index.css">


		<!-- 存放当前广告类型 -->
        <input type="hidden" id="adType">
        <!-- 透明背景 -->
        <div class="mask" style="display: none;">
        </div>
        <!-- 插入文字 -->
        <div class="fixedDiv text_insert" style="display: none; position: fixed; left: 50%; top: 50%; margin-top: -124px; margin-left: -366.5px; width: 733px;">
            <div class="tinsert_head">
                <div class="fl tinsert_hl">
                    <ul>
                        <li class="icon_bold">
                        </li>
                        <li class="icon_color">
                            <span class="nowcolor">
                            </span>
                        </li>
                        <li class="icon_bgcolor">
                        </li>
                        <li class="icon_font">
                        </li>
                        <li class="icon_align icon_left" data-align="left">
                        </li>
                        <li class="icon_align icon_center" data-align="center">
                        </li>
                        <li class="icon_align icon_right" data-align="right">
                        </li>
                    </ul>
                </div>
                <div class="fr tinsert_hr">
                    <span class="text_reset">
                        清空
                    </span>
                </div>
            </div>
            <div class="tinsert_body">
                <textarea class="text_word" placeholder="请输入内容文字">
                </textarea>
            </div>
            <div class="boxCheck2 tinsert_foot">
                <button type="button" class="boxYes">
                    提交
                </button>
                <button type="button" class="boxNo">
                    取消
                </button>
            </div>
        </div>
        <!-- 选择文字颜色 -->
        <div class="fixedDiv text_color" style="display: none; position: fixed; left: 50%; top: 50%; margin-top: -129px; margin-left: -366.5px; width: 733px;">
            <div class="text_tit">
                <span class="text_tit_l">
                    文字颜色
                </span>
                <span class="text_tit_r">
                    清空
                </span>
            </div>
            <div class="check_color">
                <ul>
                    <li>
                        <span data-color="#000000" style="background:#000000;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#0f3efe" style="background:#0f3efe;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#a97a46" style="background:#a97a46;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#03fcfe" style="background:#03fcfe;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#00f72c" style="background:#00f72c;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#ff4cfd" style="background:#ff4cfd;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#fc951e" style="background:#fc951e;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#932890" style="background:#932890;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#ff2a1a" style="background:#ff2a1a;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#fdf935" style="background:#fdf935;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#ffffff" style="background:#ffffff;border: 1px solid #ccc;">
                        </span>
                    </li>
                </ul>
            </div>
            <div class="clear">
            </div>
            <div class="boxCheck2">
                <button type="button" class="boxNo text_foot_btn">
                    标准颜色
                </button>
            </div>
        </div>
        <!-- 选择文字背景颜色 -->
        <div class="fixedDiv text_bgcolor" style="display: none; position: fixed; left: 50%; top: 50%; margin-top: -129px; margin-left: -366.5px; width: 733px;">
            <div class="text_tit">
                <span class="text_tit_l">
                    文字背景颜色
                </span>
                <span class="text_tit_r">
                    清空
                </span>
            </div>
            <div class="check_color">
                <ul>
                    <li>
                        <span data-color="#000000" style="background:#000000;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#0f3efe" style="background:#0f3efe;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#a97a46" style="background:#a97a46;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#03fcfe" style="background:#03fcfe;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#00f72c" style="background:#00f72c;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#ff4cfd" style="background:#ff4cfd;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#fc951e" style="background:#fc951e;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#932890" style="background:#932890;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#ff2a1a" style="background:#ff2a1a;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#fdf935" style="background:#fdf935;">
                        </span>
                    </li>
                    <li>
                        <span data-color="#ffffff" style="background:#ffffff;border: 1px solid #ccc;">
                        </span>
                    </li>
                </ul>
            </div>
            <div class="clear">
            </div>
            <div class="boxCheck2">
                <button type="button" class="boxNo text_foot_btn">
                    标准颜色
                </button>
            </div>
        </div>
        <!-- 文字大小 -->
        <div class="fixedDiv text_size" style="display: none; position: fixed; left: 50%; top: 50%; margin-top: -134px; margin-left: -366.5px; width: 733px;">
            <div class="text_tit">
                <span class="text_tit_l">
                    字体大小
                </span>
            </div>
            <div class="check_size">
                <ul>
                    <li>
                        10px
                    </li>
                    <li>
                        12px
                    </li>
                    <li>
                        14px
                    </li>
                    <li>
                        16px
                    </li>
                    <li>
                        18px
                    </li>
                    <li>
                        28px
                    </li>
                </ul>
            </div>
        </div>
        <!-- 插入音乐 -->
        <div class="text_music" style="display: none;">
            <div class="tmusic_top">
                <div class="header tmusic_header">
                    选择音乐
                    <a href="javascript:;" class="back" style="padding-top: 7px;">
                        <img src="__PUBLIC__/img/back.png">
                        <span class="back_cs">
                            关闭
                        </span>
                    </a>
                </div>
            </div>
            <div class="tmusic_body" id="tmusic_body">
                <div class="tmusic_body_table" style="overflow-y:auto;">
                    <table cellspacing="0" style="margin-top:10px" cellpadding="0" class="table">
                        <tbody class="music_list" style="text-align:center">							 
                        </tbody>
						<div id="loadding"></div>
                    </table>
                </div>
                <!-- <div style="" class="load_div load_div_music">
                    <span class="load_music loadmore_span">
                        加载更多
                    </span>
                </div> -->
            </div>
            <div class="header tmusic_footer">
                确定
            </div>
        </div>

        <!-- 上传图片 -->
        <!-- <input type="file" name="file" id="uploadImg" class="uploadImg" onchange="ajax_upload(this)" accept="image/*">  -->
        <input type="file" name="file" id="uploadImg" class="uploadImg" onchange="ajaxupload(this)" accept="image/*"> 
        <!-- 上传视频 -->
        <div class="text_video">
            <div class="tvideo_main">
                <div class="tvideo_tit">
                    请粘贴视频地址到下面的输入框：
                </div>
                <div class="tvideo_body">
                    <input type="text" placeholder="目前仅支持优酷、土豆" id="videoUrl" class="tvideo_inp">
                </div>
                <button type="button" class="tvideo_btn tvideo_btn_yes" style="border:0px">
                    插入
                </button>
                <button type="button" class="tvideo_btn tvideo_btn_no" style="border:0px">
                    取消
                </button>
            </div>
        </div>

        <!-- 增加新的广告 -->
        <div class="saleShare article_newad">
			<ul class="guanggao">

            </ul>
        </div>

         <!-- 增加新的产品 -->
        <div class="saleShare article_new_product">
            <ul class="product">
                
            </ul>
        </div>

		<!-- 加载图 -->
		<div id="zxloading">
			<div id="loadtext">
				<h1>
					<img src="__PUBLIC__/img/loading4.gif">
				</h1>
				<p>
					加载中，请稍候…
				</p>
			</div>
		</div>
		
		<input type="hidden" id="page" value="1">
		<script src="__PUBLIC__/js/jquery-1.7.2.min.js"></script>
		<script src="__PUBLIC__/js/xxUploadImgTemplate.js"></script>
		<script src="__PUBLIC__/js/editor.js"></script>
		<script src="__PUBLIC__/js/editor_index.js"></script>
		<script>
			$(function(){
				//音乐列表
				$.ajax({
				   type: "POST",
				   url: "<{:U('Home/Template/ajax_music_template')}>",
				   dataType:'json',
				   success: function(msg){
			
						html = '';
						var music_id = $('#form_music_id').val();

						if(msg.status != '0'){								
							for(i in msg.data){
								if(music_id == msg.data[i].id){
									var class_html = "class='on'";
								}
							
								html += '<tr data-src="'+msg.data[i].url+'" music_id="'+msg.data[i].id+'" '+class_html+'>';
								html += '<td class="tmusic_td2">';
								html += '<h1>';
								html += msg.data[i].title;
								html += '</h1>';
								html += '</td>';
								html += '<td class="tmusic_td3">';
								html += '</td>';
								html += '<td class="tmusic_td4">';
								html += '</td>';
								html += '</tr>';

								var class_html = '';
							}

							$(".music_list").html(html);
						}else{
							$(".music_list").html(msg.data);		
						}
												
					}
				});
				
			
				$(".text_music").scroll(function () {
					if($(this).scrollTop()>=($(".tmusic_body_table").height()+100-$(this).height())){
						//ajax_music();
					}
				});
			
				//增加新广告 
				$(".t_ad").live("click",function() {
					var type = $(this).attr('data-tid');
					$("#zxloading").show();
					$.ajax({
					   type: "POST",
					   url: "<{:U('Home/Template/ajax_template')}>",
					   data: "type="+type,
					   dataType:'html',
					   success: function(msg){
							$("#zxloading").hide();
							var msg = eval("(" + msg + ")");

							if(msg.status != '0'){
								html = '';					
								html += '<div style="height:200px;overflow:hidden;width:100%;overflow-y:auto;">';
								for(i in msg.data){
									html +='<li data-type="card" data-tid="'+msg.data[i].id+'" onclick="insertion(this)">';
									html += msg.data[i].title;
									html +='</li>';								
								}
								html += '</div>';									
								html +='<li class="lastli">';
								html +='取消';
								html +='</li>';
								
								$(".guanggao").html(html);
								
							}else{
								layer.open({
									content:'请去新建广告模板'
								});
								
								return false;
							}
							
							$(".article_newad").addClass("on");
							$(".mask").show();
							
							
							$(".lastli").click(function(){
								$(".article_newad").removeClass("on");
								$(".mask").hide();	
							})
								
					   }
					});
				
				});
			
			    //检测音乐dom有的话就加入,防止文章库插音乐没有音乐响
                var music = $('#media_tym').html();
                if(typeof(music) == 'undefined'){
                    $('#middle_content').append("<audio loop='' src='' id='media_tym' autoplay='autoplay' preload=''></audio>");
                }
			});
			
			//插入视频弹层 TODO
			$(".tvideo_btn_yes").live("click",function() {
					var videoUrl = $("#videoUrl").val();
						$("#zxloading").show();
					if (videoUrl) {
						$.ajax({
							url: "<{:U('Home/Article/display_iframe')}>",
							data: {
								"url": videoUrl
							},
							dataType: "json",
							success: function(data){
								var videocode = data.url;
									$("#zxloading").hide();
								if (data.error) {
									var html = '<iframe height="480" width="400" src="'+videocode+'" frameborder="0" allowfullscreen=""></iframe>';
									$(".eing").after(html);
									$("iframe").css({
										"width": "100%",
										"height": "300px"
									});
									$("#videoUrl").val('');
									cancel_action();
									close_tool();
									close_tip();
								} else {
									layer.open({
										content:'该视频地址无效，请重新粘贴！'
									});
								}
							}
						});

					} else {
						layer.open({
							content:'请粘贴视频地址！'
						});
					}
			});
			
			//加载音乐分页
			function ajax_music(){
				var page = $('#page').val();
				if(page == '-1'){
					return false;
				}
				
				//加载进度条
				layer.open({
					type: 2,
					content: '加载中'
				});
				
				$.ajax({
					type: "POST",
					url: "<{:U('Home/Template/ajax_music_page')}>",
					data: "page="+page,
					dataType:'json',
					success: function(msg){
						if(msg.status == '1'){
							var html = '';
							for(i in msg.data){							
								html += '<tr data-src="'+msg.data[i].url+'" music_id="'+msg.data[i].id+'">';
								html += '<td class="tmusic_td2">';
								html += '<h1>';
								html += msg.data[i].title;
								html += '</h1>';
								html += '</td>';
								html += '<td class="tmusic_td3">';
								html += '</td>';
								html += '<td class="tmusic_td4">';
								html += '</td>';
								html += '</tr>';			
							}

							page = parseInt(page) + 1;
							$('#page').val(page);
							$('#loadding').before(html);
							layer.closeAll();//关闭进度条
						}else{
							$('#page').val('-1');
							layer.closeAll(); //关闭进度条
						}
					}
				});
			}
					
			//插入当前元素
			function insertion(obj){
				var tid = $(obj).attr('data-tid');
				
				$.ajax({
				   type: "POST",
				   url: "<{:U('Home/Article/gain_item_info')}>",
				   data: "id="+tid,
				   success: function(msg){
					 if(msg.status == '-1'){
						layer.open({
							content:msg.msg
						});
						return false;
					 }else{
						var public_url = "<{:C('images_url')}>";
						var html  = group_type(msg,public_url);
						$(".eing").after(html);
						$(".article_newad").removeClass("on");
						$(".mask").hide();
						cancel_action();
						close_tool();
						close_tip();
					 }
				   }
				});
			}

			//上传图片(这个上传图片只能用于编辑模板)
            function ajaxupload(obj){
                var file = $(obj).get(0).files[0]; //选择上传的文件
                    
                var r = new FileReader();
                
                r.readAsDataURL(file); //Base64

                $(r).load(function(){
                    // 判断是否图片  
                    if(!file){ 
                        layer.open({
                            content:'不是图片',
                        }); 
                        return ;  
                    } 

                    //限制图片格式
                    if(!(file.type.indexOf('image')==0 && file.type && /\.(?:jpeg|jpg|png|gif)$/.test(file.name)) ){  
                        layer.open({
                            content:'图片只能是jpg,gif,png,jpeg',
                        });
                        return ;  
                    }

                    //限制大小
                    var upload_size = '<{:C("upload_size")}>';

                    if(file.size > upload_size){
                        layer.open({
                            content:'超出上传图片大小标准',
                        });
                        return ; 
                    }
                    
                    //load图
                    $.ajax({
                        url:'<{:U("Home/Index/upload_picture")}>',
                        data:{img: this.result,img_type:file.type,img_size:file.size},
                        type:"post",
                        beforeSend:function(){
                            //开始提交
                            $("#zxloading").show();
                        },
                        complete:function(){
                            //完成提交
                            $("#zxloading").hide();
                        },
                        success:function(ret){
                             var domain = '<{:C("images_url")}>';
                                      
                             html = '<img src="' + domain + ret + '" style="max-width:100%;"><br>';
                             $(".eing").after(html);
                                                      
                             cancel_action();
                             close_tool();

                             //同张图片上传多次，就要清空Input框，从新触发Onchang事件
                             $("#uploadImg").val(null); 
                        },
                    });  
           
                });
            }   		
		</script>
		